package com.sanpu.kxe.business.trade.view;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.base.BaseTitleActivity;
import com.sanpu.kxe.business.main.view.MainActivity;
import com.sanpu.kxe.module.roundview.RoundTextView;
import com.sanpu.kxe.utils.AppContextUtil;
import com.sanpu.kxe.utils.DateUtils;
import com.sanpu.kxe.utils.IntentTool;

import butterknife.Bind;

/**
 * Description：二维码支付被扫码支付成功展示
 * Created by 薛勇军 on 2018/10/25.
 */

public class PaySuccessActivity extends BaseTitleActivity {

    @Bind(R.id.state)
    TextView vState;
    @Bind(R.id.time)
    TextView vTime;
    @Bind(R.id.amount)
    TextView vAmount;
    @Bind(R.id.phone_number)
    TextView vPhoneNumber;
    @Bind(R.id.phone_layout)
    LinearLayout vPhoneLayout;
    @Bind(R.id.amount_title)
    TextView vAmountTitle;
    @Bind(R.id.amount_layout)
    LinearLayout vAmountLayout;
    @Bind(R.id.close)
    RoundTextView vClose;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_pay_success;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setTitle("交易成功");
        try {
            String amount = getIntent().getData().getQueryParameter("amount");
            String isUpgrade = getIntent().getData().getQueryParameter("isUpgrade");
            String timestamp = getIntent().getData().getQueryParameter("timestamp");

            String currencyName = getIntent().getData().getQueryParameter("currencyName");
            String unit = TextUtils.isEmpty(currencyName)?"元":currencyName;
            if (isUpgrade == null) {
                isUpgrade = "false";
            }
            switch (isUpgrade) {
                case "false":
                    vState.setText("交易成功");
                    vAmountTitle.setText("交易金额");
                    vAmount.setText(amount + unit);
                    break;
                case "true":
                    vState.setText("会员升级成功");
                    vAmountTitle.setText("升级费用");
                    vAmount.setText(amount + "元");
                    break;
                default:
                    break;
            }
            if (!TextUtils.isEmpty(timestamp)) {
                vTime.setText(DateUtils.formatTime(Long.parseLong(timestamp), "yyyy-MM-dd HH:mm:ss"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void setListener() {
        super.setListener();
        vClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IntentTool.startActivity(mContext, MainActivity.class);
                AppContextUtil.finishAllExclByActivity(MainActivity.class.getName());
            }
        });
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }
}
